<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Product_model extends CI_Model {
	
	public function __construct(){
		
		parent::__construct();

	}
	
	public function get_products_by_limit($parameter = array(),$distinct = false,$keyword = '', $limit = 0 ,$size = 9){
		
		if($parameter){
			
			if($distinct){
				
				$this->db->distinct();
				$this->db->select($keyword);
				
			}
				
			$q = $this->db->get_where('products',$parameter);
						
			return $q->result();
			
		}else{
			
			$q = $this->db->get('products',$size,$size*$limit);
			
			return $q->result();
			
		}
		
	}
	
	public function get_info($tablename='',$parameter = array(),$limit = 0,$size = 9){
		
		$q = $this->db->get_where($tablename,$parameter,$size,$size*$limit);
		
		return $q->result();
		
	}
	
	public function get_info_row($tablename='',$parameter = array()){
		
		$q = $this->db->get_where($tablename,$parameter);
		
		return $q->row();
		
	}
	
	public function get_total_nums($tablename = '',$parameter = array()){
		
		if($parameter){
			
			$q = $this->db->get_where($tablename,$parameter);
			
			return $q->num_rows();
			
		}
		
	}
	
	/*
	 * 获取分类id及其子分类id
	* */
	public function get_make_id($make_id = '',&$make_ids){
		
		if($make_id){
			
			$query = $this->db->get_where('makes',array('pid'=>$make_id));
			
			$result = $query->result_array();
			
			if($result){
				
				foreach ($result as $key=>$val){
					
					$this->get_make_id($val['make_id'],$make_ids);
				}
			}
				
			$make_ids[] = $make_id; 

		}else{
			
			return false;
		}
	}
	
	public function get_product_child_makes(){
		
		$this->db->select('pro_id,make_id');
		$q = $this->db->get('products');
		return $q->result();
		
	}
	
	public function get_main_makes($limit = '',$size = ''){
		
		$sql = "select * from makes where pid = 1";
		
		if($limit&&$size){
			
			$sql .= " $limit,$size";
		}
		
		$q = $this->db->query($sql);
	
		return $q->result();
	}
	
	
	public function get_makes($data = array()){
		
		$this->db->select('make_id,make_name,pid');
		
		if($data){
		
			$q = $this->db->get_where('makes',$data);
			
		}else{
			
			$q = $this->db->get('makes');
						
		}	

		return $q->result();
		
	}
	
	public function getmakes($data = array()){
		
		$sql = "select a.* from makes a join products b on a.make_id=b.main_make_id where";
		
		foreach($data as $k=>$v){
			
			$sql .= " b.$k=".$v;
		}
		
		$q = $this->db->query($sql);
		
		return $q->result();
	}
	
	public function get_make_name($make_id = ''){
		
		if($make_id){
			
			$q = $this->db->get_where('makes',array('make_id'=>$make_id));
			
			return $q->row();
			
		}else{
			
			return false;
		}
		
	}
	
	public function get_img($proid,$limit = false){
		
		if($proid){
			
			$q = $this->db->get_where('proimg',array('proid'=>$proid));
			
			if($limit){

				return $q->row();
			}
			
			return $q->result();
			
		}else{

			return false;
		}
		
	}
	
	public function get_partnumber($parameter = array(),$distinct = true){
		
		if($parameter){
				
			if($distinct){
		
				$this->db->distinct();
				$this->db->select('partnumberurl');
		
			}
		
			$q = $this->db->get_where('products',$parameter);
		
			return $q->result();
				
		}
	}
	
	public function get_year($parameter = array(),$distinct = true){
	
		if($parameter){
				
			if($distinct){
		
				$this->db->distinct();
				$this->db->select('year');
		
			}
		
			$q = $this->db->get_where('products',$parameter);
		
			return $q->result();
				
		}
	}
	
	public function get_model($parameter = array(),$distinct = true){
	
		if($parameter){
				
			if($distinct){
		
				$this->db->distinct();
				$this->db->select('model');
		
			}
		
			$q = $this->db->get_where('products',$parameter);
		
			return $q->result();
				
		}
	}
	
	
	
	
	
	
	
	
	
	
	
}